export class Tile {
  x: number;
  y: number;
  value: number;
  isOnBound: boolean = false; // 是否在边界上
  isSelected: boolean = false; //是否选中状态
  constructor(position: { x: number; y: number; }, value: number, isOnBound: boolean) {
    this.x = position.x;
    this.y = position.y;
    this.value = value || 2; // 默认初始化值 2
    this.isOnBound = isOnBound;
  }

  updatePosition(position: { x: any; y: any; }) {
    this.x = position.x;
    this.y = position.y;
  }

  setLight() {
    this.isSelected = true;
  }

  clearLight() {
    this.isSelected = false;
  }

  serialize() {
    // 序列化返回位置和值对象
    return {
      position: {
        x: this.x,
        y: this.y
      },
      value: this.value,
      isOnBound: this.isOnBound,
      isSelected:this.isSelected
    };
  }
}